<?php

namespace Action\User\Preferences;

class ChangeAuth extends \Library\Action\UserAction 
	implements \Library\Action\AjaxAction {

	public function execute() {
		parent::execute();
		
		$params = $this->getParams();
		$user = _u();
		
		_a( preg_match( '/^[A-Za-z]+$/', $params['kind'] ), 'Invalid authentication method' );
		$auth = \Library\Auth::get( $params['kind'] );

		//if( $auth->isChangeable( $user ) ) {
			$auth->change( $params );
		//}
		
		$sessionConf = \Library\Config::get( 'session' );
		$session = \Library\Auth\Session::getSession();
		
		$session->setUser( $user );
		
		return true;
	}

}
